#include <iostream>
#include <algorithm>
using namespace std;
constexpr int MAXN = 300;
int n, a[MAXN];
int main() {
    freopen("./input.txt", "r", stdin);

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    
    sort(a, a + n, [&](int x, int y){
        return y - x;
    });

    int count = 0;
    for (int i = 0; i < n - 3; i++)
        if (a[i] < a[i + 1] + a[i + 2]) {
            cout << a[i] + a[i + 1] + a[i + 2];
            return 0;
        }
    cout << "0";
    return 0;
}